package ar.com.juanlopezcervero.flexigrid4j.params;

import java.io.Serializable;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

public class FlexigridButton extends FlexigridItem implements Serializable {

	private static final long serialVersionUID = 2297445607303493562L;

//	{name: 'Borrar', bclass: 'delete', onpress : deleteCenter},
//  {separator: true}

	private String name;
	private String bclass;
	private String onpress;
	
	private Boolean separator;
	
	public FlexigridButton() {
		super();
	}
	
	public static FlexigridButton createSeparator() {
		FlexigridButton separatorButton = new FlexigridButton();
		separatorButton.setSeparator(Boolean.TRUE);
		return separatorButton;
	}
	
	/**
	 * {name: 'Borrar', bclass: 'delete', onpress : deleteCenter},
	 * @param name
	 * @param bclass
	 * @param onpress
	 */
	public FlexigridButton(String name, String bclass, String onpress) {
		this.name = name;
		this.bclass = bclass;
		this.onpress = onpress;
	}
	
	@Override
	public JSONObject getJSONObejct() throws JSONException {
		JSONObject jsonObject = new JSONObject();
		if (separator == null || !separator) {
			jsonObject.putOpt("name", name);
			jsonObject.putOpt("bclass", bclass);
			jsonObject.putOpt("onpress", onpress);
		} else {
			jsonObject.putOpt("separator", separator);
		}
		return jsonObject;
	}
	
	
	public String getName() {
		return name;
	}
	/**
	 * Button name
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	public String getBclass() {
		return bclass;
	}
	/**
	 * CSS Class for button
	 * @param bclass
	 */
	public void setBclass(String bclass) {
		this.bclass = bclass;
	}
	public String getOnpress() {
		return onpress;
	}
	/**
	 * javascript callback function
	 * @param onpress
	 */
	public void setOnpress(String onpress) {
		this.onpress = onpress;
	}
	public Boolean getSeparator() {
		return separator;
	}
	/**
	 * Button separator
	 * @param separator
	 */
	public void setSeparator(Boolean separator) {
		this.separator = separator;
	}
	
}
